import UniformScaleBase from "../NRLib/Component/UniformScaleBase";
import DebugExt from "../NRLib/base/DebugExt";

const { ccclass, property } = cc._decorator;

/** SDK安全区适配-需要缩放、移动主显示区域 */
@ccclass
export default class ZegoSafeFit extends UniformScaleBase {

    protected doUniformScale() {
        if (!this.active) return;
        const safeArea: yy.ISafeArea = CC_PREVIEW ? { paddingTop: 20, paddingBottom: 60, paddingLeft: 0, paddingRight: 0 } : yy.thirdPlatform.getSafeArea();
        DebugExt.debug("[ZegoSafeFit] 第三方缩放参数：", safeArea);
        if (!safeArea || safeArea.paddingBottom + safeArea.paddingTop <= 0) return;
        // 缩放
        const designHeight = this.designSize.height;
        const heightFit = designHeight - safeArea.paddingTop - safeArea.paddingBottom;
        if (heightFit <= 0) {
            DebugExt.warn("安全区配置异常，剩余可展示区域高度为：", heightFit);
            return;
        }
        const scale = heightFit / designHeight;
        this.scaleRelative = scale;
        // 位移
        const deltaY = (safeArea.paddingBottom - safeArea.paddingTop) / 2;
        this.node.setPosition(0, deltaY);
        DebugExt.debug("[ZegoSafeFit] scale:", scale, " position y：", deltaY);
    }
}
